package org.example.shop.service;

import org.example.shop.entity.Goods;
import org.example.shop.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    //返回所有的商品数据
    public List<Goods> selectAll() {
        return goodsMapper.selectAll();
    }
    public List<Goods> selectAllNew() {
        return goodsMapper.selectAllNew();
    }
    // 添加分页方法
    private static final int DEFAULT_PAGE_SIZE = 6; // 默认每页显示6条

    public List<Goods> findByPage(int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return goodsMapper.selectByPage(offset, pageSize);
    }

    public long count() {
        return goodsMapper.count();
    }
    public List<Goods> selectAllHot() {
        return goodsMapper.selectAllHot();
    }

    public List<Goods> selectHotRandom() {
        return goodsMapper.selectHotRandom();
    }
}
